package com.bs.areport.service.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bs.areport.service.util.EntityType;
import com.bs.restframework.context.util.SystemContextUtil;
import com.bs.restframework.db.Database;
/**
 * 
 * <p>函数名称：数据对象类型</p>
 * <p>创建时间：2012-03-07</p>
 * <p>作者：李新宇</p>
 *
 */
public class EntityType {
	
	/**
	  * <p>表数据类型定义</p>
	  */
	public static final char ARP_SET = 0;

	public static final String ARP_SET_TABLE = "ARP_SET";

	public static  Map<String, String> ARP_SET_MAP = new HashMap<String, String>();
	static {
	    ARP_SET_MAP.put("F_ID", "F_ID|VARCHAR2|50|||N||");
	    ARP_SET_MAP.put("F_OBJ", "F_OBJ|VARCHAR2|200|||N||");
	    ARP_SET_MAP.put("F_ITEM1", "F_ITEM1|VARCHAR2|200|||Y||");
	    ARP_SET_MAP.put("F_ITEM2", "F_ITEM2|VARCHAR2|200|||Y||");
	    ARP_SET_MAP.put("F_ITEM3", "F_ITEM3|VARCHAR2|200|||Y||");
	    ARP_SET_MAP.put("F_ITEM4", "F_ITEM4|VARCHAR2|200|||Y||");
	    ARP_SET_MAP.put("F_ITEM5", "F_ITEM5|VARCHAR2|200|||Y||");
	    ARP_SET_MAP.put("F_ITEM6", "F_ITEM6|VARCHAR2|200|||Y||");
	    ARP_SET_MAP.put("F_ITEM7", "F_ITEM7|VARCHAR2|200|||Y||");
	    ARP_SET_MAP.put("F_ITEM8", "F_ITEM8|VARCHAR2|200|||Y||");
	    ARP_SET_MAP.put("F_ITEM9", "F_ITEM9|FLOAT|22|126||Y||");
	    ARP_SET_MAP.put("F_ITEM10", "F_ITEM10|FLOAT|22|126||Y||");
	}

	public static final char ARP_BSC_CHARGE = 1;

	public static final String ARP_BSC_CHARGE_TABLE = "ARP_BSC_CHARGE";

	public static  Map<String, String> ARP_BSC_CHARGE_MAP = new HashMap<String, String>();
	static {
	    ARP_BSC_CHARGE_MAP.put("F_ID", "F_ID|VARCHAR2|50|||N||");
	    ARP_BSC_CHARGE_MAP.put("F_CODE", "F_CODE|VARCHAR2|50|||N||");
	    ARP_BSC_CHARGE_MAP.put("F_NAME", "F_NAME|VARCHAR2|120|||N||");
	    ARP_BSC_CHARGE_MAP.put("F_CHRGATTR", "F_CHRGATTR|VARCHAR2|80|||Y||");
	    ARP_BSC_CHARGE_MAP.put("F_MSRUNIT", "F_MSRUNIT|VARCHAR2|30|||Y||");
	    ARP_BSC_CHARGE_MAP.put("F_FEEGIST", "F_FEEGIST|VARCHAR2|80|||Y||");
	    ARP_BSC_CHARGE_MAP.put("F_PAYRATIO", "F_PAYRATIO|NUMBER|22||0|Y||");
	    ARP_BSC_CHARGE_MAP.put("F_DIVIRATIO", "F_DIVIRATIO|VARCHAR2|50|||Y||");
	    ARP_BSC_CHARGE_MAP.put("F_ISCOLL", "F_ISCOLL|VARCHAR2|1|||Y||");
	    ARP_BSC_CHARGE_MAP.put("F_MNEM", "F_MNEM|VARCHAR2|60|||Y||");
	    ARP_BSC_CHARGE_MAP.put("F_LEVEL", "F_LEVEL|NUMBER|22||0|N||");
	    ARP_BSC_CHARGE_MAP.put("F_ISLEAF", "F_ISLEAF|NUMBER|22||0|N||");
	    ARP_BSC_CHARGE_MAP.put("F_LASTTIME", "F_LASTTIME|VARCHAR2|17|||N||");
	}

	public static final char ARP_BSC_GVNDEPT = 2;

	public static final String ARP_BSC_GVNDEPT_TABLE = "ARP_BSC_GVNDEPT";

	public static  Map<String, String> ARP_BSC_GVNDEPT_MAP = new HashMap<String, String>();
	static {
	    ARP_BSC_GVNDEPT_MAP.put("F_ID", "F_ID|VARCHAR2|50|||N||");
	    ARP_BSC_GVNDEPT_MAP.put("F_CODE", "F_CODE|VARCHAR2|50|||N||");
	    ARP_BSC_GVNDEPT_MAP.put("F_NAME", "F_NAME|VARCHAR2|200|||N||");
	    ARP_BSC_GVNDEPT_MAP.put("F_MNEM", "F_MNEM|VARCHAR2|60|||Y||");
	    ARP_BSC_GVNDEPT_MAP.put("F_LEVEL", "F_LEVEL|NUMBER|22||0|Y||");
	    ARP_BSC_GVNDEPT_MAP.put("F_ISLEAF", "F_ISLEAF|NUMBER|22||0|Y||");
	    ARP_BSC_GVNDEPT_MAP.put("F_LASTTIME", "F_LASTTIME|VARCHAR2|17|||Y||");
	}

	public static final char ARP_BUS_DAYLOG = 3;

	public static final String ARP_BUS_DAYLOG_TABLE = "ARP_BUS_DAYLOG";

	public static  Map<String, String> ARP_BUS_DAYLOG_MAP = new HashMap<String, String>();
	static {
	    ARP_BUS_DAYLOG_MAP.put("F_ID", "F_ID|VARCHAR2|50|||N||");
	    ARP_BUS_DAYLOG_MAP.put("F_DEPTID", "F_DEPTID|VARCHAR2|50|||N||");
	    ARP_BUS_DAYLOG_MAP.put("F_BGNDATE", "F_BGNDATE|VARCHAR2|8|||Y||");
	    ARP_BUS_DAYLOG_MAP.put("F_ENDDATE", "F_ENDDATE|VARCHAR2|8|||N||");
	    ARP_BUS_DAYLOG_MAP.put("F_MON", "F_MON|VARCHAR2|6|||Y||");
	    ARP_BUS_DAYLOG_MAP.put("F_LASTTIME", "F_LASTTIME|VARCHAR2|17|||Y||");
	}

	public static final char ARP_BUS_CHRGMON = 4;

	public static final String ARP_BUS_CHRGMON_TABLE = "ARP_BUS_CHRGMON";

	public static  Map<String, String> ARP_BUS_CHRGMON_MAP = new HashMap<String, String>();
	static {
	    ARP_BUS_CHRGMON_MAP.put("F_ID", "F_ID|VARCHAR2|50|||N||");
	    ARP_BUS_CHRGMON_MAP.put("F_MON", "F_MON|VARCHAR2|6|||Y||");
	    ARP_BUS_CHRGMON_MAP.put("F_DEPTID", "F_DEPTID|VARCHAR2|50|||Y||");
	    ARP_BUS_CHRGMON_MAP.put("F_CHRGID", "F_CHRGID|VARCHAR2|50|||Y||");
	    ARP_BUS_CHRGMON_MAP.put("F_CNT", "F_CNT|NUMBER|22||0|Y||");
	    ARP_BUS_CHRGMON_MAP.put("F_AMT", "F_AMT|NUMBER|22|||Y||");
	    ARP_BUS_CHRGMON_MAP.put("F_LASTTIME", "F_LASTTIME|VARCHAR2|17|||Y||");
	}

	public static final char ARP_BUS_CHRGDAY = 5;

	public static final String ARP_BUS_CHRGDAY_TABLE = "ARP_BUS_CHRGDAY";

	public static  Map<String, String> ARP_BUS_CHRGDAY_MAP = new HashMap<String, String>();
	static {
	    ARP_BUS_CHRGDAY_MAP.put("F_ID", "F_ID|VARCHAR2|50|||N||");
	    ARP_BUS_CHRGDAY_MAP.put("F_DATE", "F_DATE|VARCHAR2|8|||Y||");
	    ARP_BUS_CHRGDAY_MAP.put("F_DEPTID", "F_DEPTID|VARCHAR2|50|||Y||");
	    ARP_BUS_CHRGDAY_MAP.put("F_CHRGID", "F_CHRGID|VARCHAR2|50|||Y||");
	    ARP_BUS_CHRGDAY_MAP.put("F_CNT", "F_CNT|NUMBER|22||0|Y||");
	    ARP_BUS_CHRGDAY_MAP.put("F_AMT", "F_AMT|NUMBER|22|||Y||");
	    ARP_BUS_CHRGDAY_MAP.put("F_LASTTIME", "F_LASTTIME|VARCHAR2|17|||Y||");
	}

	public static final char SYS_USER = 6;

	public static final String SYS_USER_TABLE = "SYS_USER";

	public static  Map<String, String> SYS_USER_MAP = new HashMap<String, String>();
	static {
	    SYS_USER_MAP.put("F_ID", "F_ID|VARCHAR2|50|||N||");
	    SYS_USER_MAP.put("F_CODE", "F_CODE|VARCHAR2|50|||N||");
	    SYS_USER_MAP.put("F_NAME", "F_NAME|VARCHAR2|200|||N||");
	    SYS_USER_MAP.put("F_PASSWORD", "F_PASSWORD|VARCHAR2|20|||N||");
	    SYS_USER_MAP.put("F_PHONENO", "F_PHONENO|VARCHAR2|20|||Y||");
	    SYS_USER_MAP.put("F_USERGROUPID", "F_USERGROUPID|VARCHAR2|50|||N||");
	    SYS_USER_MAP.put("F_USERROLEID", "F_USERROLEID|VARCHAR2|50|||Y||");
	    SYS_USER_MAP.put("F_STATE", "F_STATE|VARCHAR2|1|||Y||");
	    SYS_USER_MAP.put("F_USERTYPE", "F_USERTYPE|VARCHAR2|1|||N||");
	    SYS_USER_MAP.put("F_DEPTID", "F_DEPTID|VARCHAR2|50|||Y||");
	    SYS_USER_MAP.put("F_MENO", "F_MENO|VARCHAR2|200|||Y||");
	    SYS_USER_MAP.put("F_HIGHTUP", "F_HIGHTUP|VARCHAR2|50|||Y||");
	    SYS_USER_MAP.put("F_LASTTIME", "F_LASTTIME|VARCHAR2|17|||Y||");
	}

	public static final char SYS_RIGHT = 7;

	public static final String SYS_RIGHT_TABLE = "SYS_RIGHT";

	public static  Map<String, String> SYS_RIGHT_MAP = new HashMap<String, String>();
	static {
	    SYS_RIGHT_MAP.put("F_ACTION", "F_ACTION|VARCHAR2|100|||Y||");
	    SYS_RIGHT_MAP.put("F_ID", "F_ID|VARCHAR2|50|||N||");
	    SYS_RIGHT_MAP.put("F_CODE", "F_CODE|VARCHAR2|50|||N||");
	    SYS_RIGHT_MAP.put("F_NAME", "F_NAME|VARCHAR2|200|||N||");
	    SYS_RIGHT_MAP.put("F_LEVEL", "F_LEVEL|NUMBER|22||0|N||");
	    SYS_RIGHT_MAP.put("F_ISLEAF", "F_ISLEAF|NUMBER|22||0|N||");
	    SYS_RIGHT_MAP.put("F_LASTTIME", "F_LASTTIME|VARCHAR2|17|||Y||");
	    SYS_RIGHT_MAP.put("F_ISMENU", "F_ISMENU|VARCHAR2|1|||N||");
	}

	public static final char ARP_BSC_DEPT = 8;

	public static final String ARP_BSC_DEPT_TABLE = "ARP_BSC_DEPT";

	public static  Map<String, String> ARP_BSC_DEPT_MAP = new HashMap<String, String>();
	static {
	    ARP_BSC_DEPT_MAP.put("F_STATE", "F_STATE|VARCHAR2|1|||N||");
	    ARP_BSC_DEPT_MAP.put("F_ID", "F_ID|VARCHAR2|50|||N||");
	    ARP_BSC_DEPT_MAP.put("F_CODE", "F_CODE|VARCHAR2|50|||N||");
	    ARP_BSC_DEPT_MAP.put("F_NAME", "F_NAME|VARCHAR2|200|||N||");
	    ARP_BSC_DEPT_MAP.put("F_MNEM", "F_MNEM|VARCHAR2|100|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_LEVEL", "F_LEVEL|NUMBER|22||0|N||");
	    ARP_BSC_DEPT_MAP.put("F_ISLEAF", "F_ISLEAF|NUMBER|22||0|N||");
	    ARP_BSC_DEPT_MAP.put("F_LASTTIME", "F_LASTTIME|VARCHAR2|17|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_LINKMAN", "F_LINKMAN|VARCHAR2|30|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_PHONE", "F_PHONE|VARCHAR2|30|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_ADDR", "F_ADDR|VARCHAR2|200|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_PURCNO", "F_PURCNO|VARCHAR2|30|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_TYPE", "F_TYPE|VARCHAR2|20|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_GVNDEPTID", "F_GVNDEPTID|VARCHAR2|50|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_PURCDATE", "F_PURCDATE|VARCHAR2|8|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_UNITYCODE", "F_UNITYCODE|VARCHAR2|50|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_MEMO", "F_MEMO|VARCHAR2|1000|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_BANK", "F_BANK|VARCHAR2|80|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_ACCOUNT", "F_ACCOUNT|VARCHAR2|120|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_NTCODE", "F_NTCODE|VARCHAR2|50|||Y||");
	    ARP_BSC_DEPT_MAP.put("F_NTNAME", "F_NTNAME|VARCHAR2|120|||Y||");
            ARP_BSC_DEPT_MAP.put("F_STATE", "F_STATE|VARCHAR2|1|||N||");
	}

	public static final char SYS_USERRIGHT = 9;

	public static final String SYS_USERRIGHT_TABLE = "SYS_USERRIGHT";

	public static  Map<String, String> SYS_USERRIGHT_MAP = new HashMap<String, String>();
	static {
	    SYS_USERRIGHT_MAP.put("F_RIGHTID", "F_RIGHTID|VARCHAR2|50|||Y||");
	    SYS_USERRIGHT_MAP.put("F_LASTTIME", "F_LASTTIME|VARCHAR2|17|||Y||");
	    SYS_USERRIGHT_MAP.put("F_ID", "F_ID|VARCHAR2|50|||N||");
	    SYS_USERRIGHT_MAP.put("F_USERID", "F_USERID|VARCHAR2|50|||Y||");
	}

	public static final char SYS_USERGROUP = 10;

	public static final String SYS_USERGROUP_TABLE = "SYS_USERGROUP";

	public static  Map<String, String> SYS_USERGROUP_MAP = new HashMap<String, String>();
	static {
	    SYS_USERGROUP_MAP.put("F_LASTTIME", "F_LASTTIME|VARCHAR2|17|||Y||");
	    SYS_USERGROUP_MAP.put("F_DEPTID", "F_DEPTID|VARCHAR2|32|||Y||");
	    SYS_USERGROUP_MAP.put("F_ID", "F_ID|VARCHAR2|50|||N|ID|");
	    SYS_USERGROUP_MAP.put("F_CODE", "F_CODE|VARCHAR2|50|||N|编码|");
	    SYS_USERGROUP_MAP.put("F_NAME", "F_NAME|VARCHAR2|200|||N|名称|");
	    SYS_USERGROUP_MAP.put("F_MEMO", "F_MEMO|VARCHAR2|200|||Y||");
	}

	/**
	  *
	  * <p>函数名称：getTableName</p>
	  * <p>功能说明：获取数据源表名</p>
	  * <p>参数说明：type: 数据对象类型</p>
	  * <p>创建时间：2012-03-07</p>
	  * <p>作者：李新宇</p>
	 */
	public static String getTableName(char type) {

	    String tableNameString="";

	    switch (type) {
	        case ARP_SET:
	        tableNameString=ARP_SET_TABLE;
	        break;
	        case ARP_BSC_CHARGE:
	        tableNameString=ARP_BSC_CHARGE_TABLE;
	        break;
	        case ARP_BSC_GVNDEPT:
	        tableNameString=ARP_BSC_GVNDEPT_TABLE;
	        break;
	        case ARP_BUS_DAYLOG:
	        tableNameString=ARP_BUS_DAYLOG_TABLE;
	        break;
	        case ARP_BUS_CHRGMON:
	        tableNameString=ARP_BUS_CHRGMON_TABLE;
	        break;
	        case ARP_BUS_CHRGDAY:
	        tableNameString=ARP_BUS_CHRGDAY_TABLE;
	        break;
	        case SYS_USER:
	        tableNameString=SYS_USER_TABLE;
	        break;
	        case SYS_RIGHT:
	        tableNameString=SYS_RIGHT_TABLE;
	        break;
	        case ARP_BSC_DEPT:
	        tableNameString=ARP_BSC_DEPT_TABLE;
	        break;
	        case SYS_USERRIGHT:
	        tableNameString=SYS_USERRIGHT_TABLE;
	        break;
	        case SYS_USERGROUP:
	        tableNameString=SYS_USERGROUP_TABLE;
	        break;
	    }
	    return tableNameString;
	}
	/**
	  *
	  * <p>函数名称：getTypeMap</p>
	  * <p>功能说明：获取表字段与客户端参数字段对应列表</p>
	  * <p>参数说明：type: 数据对象类型</p>
	  * <p>创建时间：2012-03-07</p>
	  * <p>作者：李新宇</p>
	 */
	public static Map<String, String> getTypeMap(char type) {

	    Map<String, String> reMap=null;

	    switch (type) {
	        case ARP_SET:
	        reMap=ARP_SET_MAP;
	        break;
	        case ARP_BSC_CHARGE:
	        reMap=ARP_BSC_CHARGE_MAP;
	        break;
	        case ARP_BSC_GVNDEPT:
	        reMap=ARP_BSC_GVNDEPT_MAP;
	        break;
	        case ARP_BUS_DAYLOG:
	        reMap=ARP_BUS_DAYLOG_MAP;
	        break;
	        case ARP_BUS_CHRGMON:
	        reMap=ARP_BUS_CHRGMON_MAP;
	        break;
	        case ARP_BUS_CHRGDAY:
	        reMap=ARP_BUS_CHRGDAY_MAP;
	        break;
	        case SYS_USER:
	        reMap=SYS_USER_MAP;
	        break;
	        case SYS_RIGHT:
	        reMap=SYS_RIGHT_MAP;
	        break;
	        case ARP_BSC_DEPT:
	        reMap=ARP_BSC_DEPT_MAP;
	        break;
	        case SYS_USERRIGHT:
	        reMap=SYS_USERRIGHT_MAP;
	        break;
	        case SYS_USERGROUP:
	        reMap=SYS_USERGROUP_MAP;
	        break;
	    }
	    return reMap;
	}


    public void CreateCode(){
		Database db=SystemContextUtil.getDatabase(this);
		String sql="select table_Name from user_tables";
		List<String> tblist = db.queryList(String.class, sql,null);
		List<String> collist=null;
		
		System.out.println("/**");
		System.out.println("  * <p>表数据类型定义</p>");
		System.out.println("  */");
		for(int i=0;i<tblist.size();i++){
			System.out.println("public static final char "+tblist.get(i).toUpperCase()+" = "+i+";");
			System.out.println("");
			System.out.println("public static final String "+tblist.get(i).toUpperCase()+"_TABLE = \""+tblist.get(i).toUpperCase()+"\";");
			System.out.println("");
			System.out.println("public static  Map<String, String> "+tblist.get(i).toUpperCase()+"_MAP = new HashMap<String, String>();");
			System.out.println("static {");
			sql="select COLUMN_NAME from user_tab_columns where table_name ='"+tblist.get(i).toUpperCase()+"'";
			collist=db.queryList(String.class, sql,null);
			for(int g=0;g<collist.size();g++){
			    System.out.println("    "+tblist.get(i).toUpperCase()+"_MAP.put(\""+collist.get(g).toUpperCase().substring(2, collist.get(g).length())+"\", \""+collist.get(g).toUpperCase()+"\");");
			}
			System.out.println("}");
			System.out.println("");
		}
		
		System.out.println("/**");
		System.out.println("  *");
		System.out.println("  * <p>函数名称：getTableName</p>");
		System.out.println("  * <p>功能说明：获取数据源表名</p>");
		System.out.println("  * <p>参数说明：type: 数据对象类型</p>");
		System.out.println("  * <p>创建时间：2012-03-07</p>");
		System.out.println("  * <p>作者：李新宇</p>");
		System.out.println(" */");
		System.out.println("public static String getTableName(char type) {");
		System.out.println("");
		System.out.println("    String tableNameString=\"\";");
		System.out.println("");
		System.out.println("    switch (type) {");
		for(int i=0;i<tblist.size();i++){
		    System.out.println("        case "+tblist.get(i).toUpperCase()+":");
		    System.out.println("        tableNameString="+tblist.get(i).toUpperCase()+"_TABLE;");
		    System.out.println("        break;");
		}
		System.out.println("    }");
		System.out.println("    return tableNameString;");
		System.out.println("}");
		
		System.out.println("/**");
		System.out.println("  *");
		System.out.println("  * <p>函数名称：getTypeMap</p>");
		System.out.println("  * <p>功能说明：获取表字段与客户端参数字段对应列表</p>");
		System.out.println("  * <p>参数说明：type: 数据对象类型</p>");
		System.out.println("  * <p>创建时间：2012-03-07</p>");
		System.out.println("  * <p>作者：李新宇</p>");
		System.out.println(" */");
		System.out.println("public static Map<String, String> getTypeMap(char type) {");
		System.out.println("");
		System.out.println("    Map<String, String> reMap=null;");
		System.out.println("");
		System.out.println("    switch (type) {");
		for(int i=0;i<tblist.size();i++){
		    System.out.println("        case "+tblist.get(i).toUpperCase()+":");
		    System.out.println("        reMap="+tblist.get(i).toUpperCase()+"_MAP;");
		    System.out.println("        break;");
		}
		System.out.println("    }");
		System.out.println("    return reMap;");
		System.out.println("}");
	}
}
